package com.fengye.security.security.auth.ldap;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

@Service
@Slf4j
@RequiredArgsConstructor
public class LdapUserDetailsService implements UserDetailsService {

    private final LdapUserRepository ldapUserRepository;
    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        log.debug("username = {}", username);
        LdapUser ldapUser = ldapUserRepository.findByUsername(username).orElseThrow(() -> new UsernameNotFoundException("ldap中未找到" + username));
        log.debug("ldapUser = {}", ldapUser);
        return ldapUser;
    }
}
